package dk.dtu.is.gui;

import dk.dtu.is.utility.jess.BeanSupport;

public class UpdateGui extends BeanSupport{
	
	MainWindow window;

	/**
	 * Communication layer between Jess engine and the java GUI
	 */
	public float value;

	public UpdateGui() {                   //constructor
		window = new MainWindow();
	}
	public void refreshCurrent(double current) {
		window.updateCurrentLabel(current);
		window.refreshGUI();
	}
	public void refreshVoltage(double voltage) {
		window.updateVoltageLabel(voltage);
		window.refreshGUI();
	}
	public void refreshSoc(double soc) {
		window.updateBatterySOC(soc*100);
		window.refreshGUI();
	}
	public void updateCurrent(String message){
		window.addStatusListItem(message);
		window.refreshGUI();
	}
	public void updateBatteryStatus(String status){
		window.updateStatusLabel(status);
		window.addStatusListItem("Battery is "+status);
		window.refreshGUI();
	}
	public void updateVoltage(String message){
		window.addStatusListItem(message);
		window.refreshGUI();
	}
	public void updateSoc(String message){
		window.addStatusListItem(message);
		window.refreshGUI();
	}
	public void updateCell(String message,int node,int id){
		window.updateCell(message, node, id);
		window.refreshGUI();
	}
	
	public void emptyStatusList() {
		System.out.println("List emptied");
		window.emptyStatusList();
	}
	
//	public boolean isGUIReady(){
//		return window.isGUILoaded();
//	}
	
	public void updateCellDiff(int id1, int id2, int node1, int node2){
		String temp;
		if (node1==node2){
		   temp="Cell voltage difference exceeded between cell " +Integer.toString(id1)+" and cell "+Integer.toString(id2)+" in node "+Integer.toString(node1);
		   window.addStatusListItem(temp);
		   window.updateCell(temp, node1, id1);
		   window.updateCell(temp, node2, id2);
		}
		else{
		   temp="Cell voltage difference exceeded between cell 10 and cell 1 between nodes " +Integer.toString(node1)+" and "+Integer.toString(node2);
		   window.addStatusListItem(temp);
		   window.updateCell(temp, node1, 10);
		   window.updateCell(temp, node2, 1);
		}
		window.refreshGUI();
	}

}
